﻿/**
 * Stardust Particle Engine
 * 
 * Homepage
 * 	http://code.google.com/p/stardust-particle-engine/
 * 
 * PDF Manual
 * 	http://stardust-particle-engine.googlecode.com/svn/trunk/manual/Stardust%20Particle%20Engine%20Manual.pdf
 */

package {
	import com.bit101.components.PushButton;
	import de.nulldesign.nd3d.renderer.Renderer;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.filters.BlurFilter;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.utils.getTimer;
	import flash.utils.Timer;
	import idv.cjcat.stardust.common.clocks.ImpulseClock;
	import idv.cjcat.stardust.common.emitters.Emitter;
	import idv.cjcat.stardust.twoD.renderers.PixelRenderer;
	
	[SWF(backgroundColor="#000000", frameRate=60)]
	
	public class Main extends Sprite {
		
		private var emitter:Emitter;
		private var renderer:Renderer;
		private var canvasBMP:Bitmap;
		
		public function Main():void {
			
			
			//UI
			//------------------------------------------------------------------------------------------------
				
				//speed buttons
				var btn1X:PushButton = new PushButton(this, 10, 10, "1X", changeSpeed);
				var btn2X:PushButton = new PushButton(this, 10, 30, "2X", changeSpeed);
				var btn4X:PushButton = new PushButton(this, 10, 50, "4X", changeSpeed);
				addEventListener(Event.ENTER_FRAME, mainLoop);
				
			//------------------------------------------------------------------------------------------------
		}
		
		private function changeSpeed(e:Event):void {
			var btn:PushButton = e.target as PushButton;
			
			if (btn.label == "1X") emitter.stepTimeInterval = 1;
			else if (btn.label == "2X") emitter.stepTimeInterval = 2;
			else if (btn.label == "4X") emitter.stepTimeInterval = 4;
		}
		
		private function mainLoop(e:Event):void {
			emitter.step();
		}
	}
}

//------------------------------------------------------------------------------------------------

import flash.display.Shape;
import idv.cjcat.stardust.common.clocks.Clock;
import idv.cjcat.stardust.common.clocks.SteadyClock;
import idv.cjcat.stardust.common.initializers.Color;
import idv.cjcat.stardust.common.initializers.Mass;
import idv.cjcat.stardust.common.math.UniformRandom;
import idv.cjcat.stardust.twoD.actions.Deflect;
import idv.cjcat.stardust.twoD.actions.Gravity;
import idv.cjcat.stardust.twoD.actions.Move;
import idv.cjcat.stardust.twoD.actions.SpeedLimit;
import idv.cjcat.stardust.twoD.deflectors.WrappingBox;
import idv.cjcat.stardust.twoD.emitters.Emitter2D;
import idv.cjcat.stardust.twoD.fields.BitmapField;
import idv.cjcat.stardust.twoD.initializers.Position;
import idv.cjcat.stardust.twoD.zones.RectZone;

//------------------------------------------------------------------------------------------------

const FLAME_COLOR:uint = 0xCC0000;

const LIFE_AVG:Number = 50;
const LIFE_VAR:Number = 10;
const SPEED_AVG:Number = 4;
const SPEED_VAR:Number = 2;
const MASS_AVG:Number = 1;
const MASS_VAR:Number = 0.3;
const GRAVITY:Number = 0.1;

const PERLIN_SEED:int = 0;

//------------------------------------------------------------------------------------------------

class FlameEmitter extends Emitter2D {
	
	public function FlameEmitter() {
		super(new SteadyClock());
		
		
		//initializers
		addInitializer(new Color(0x00CCFF));
		addInitializer(new Mass(new UniformRandom(3, 1)));
		addInitializer(new Position(new RectZone(0, 0, 465, 465)));
		
		//actions
		var deflect:Deflect = new Deflect();
		deflect.addDeflector(new WrappingBox(0, 0, 465, 465));
		
		var gravity:Gravity = new Gravity();
		field = new BitmapField();
		field.scaleX = field.scaleY = 2;
		field.massless = false;
		gravity.addField(field);
		
		addAction(deflect);
		addAction(gravity);
		addAction(new SpeedLimit(3));
		addAction(new Move());
	}
}

//------------------------------------------------------------------------------------------------

class Flame extends Shape {
	
	
}